/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controlador;

import config.Constantes;
import config.Inicializador;
import interfaz.Importar;
import interfaz.Inicio;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.apache.log4j.Priority;
import org.apache.log4j.Logger;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import main.PDFUtils;

/**
 *
 * @author freixo
 */
public class ControladorPrincipal {
    
    private static JPanel panelVisible;
    private static JFrame jframePrincipal;
    private static JFileChooser jfc;
    private static Boolean fichero;

    public static void Explorar() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    public static void ImportarPDFDesdeCarpeta() {

        jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        jfc.showOpenDialog(panelVisible);
        fichero = false;
        for(File f: jfc.getSelectedFile().listFiles()){
            try {
                File salida = new File(ClassLoader.getSystemClassLoader().getResource(".").getPath()+Constantes.DIRECTORIO_RAIZ_INDICE+f.getName().substring(0, f.getName().lastIndexOf("."))+".txt");
                BufferedWriter out = new BufferedWriter(new FileWriter(salida));
                out.write(PDFUtils.pdftoText(f));
                out.close();
            }
            catch (IOException ex) {
                Logger.getLogger(ControladorPrincipal.class.getName()).log(Priority.FATAL, null, ex);
            }
        }
        //convertir a txt e importar
        
    }

    public ControladorPrincipal() {
        
        Inicio i = new Inicio();
        panelVisible=i.getjPanel1();
        jframePrincipal= i;
        i.setVisible(true);
      
    }
    
    public static void Importar(){
        Importar i = new Importar();
        panelVisible.setVisible(false);
        panelVisible= i;     
        jframePrincipal.setContentPane(panelVisible);
        panelVisible.setVisible(true);
        jframePrincipal.pack();
        jfc = new JFileChooser();
    }
    
    
    
    
    
    
    
    
}
